<template>
  <div class='search'>
    <f-form ref='form' :action='api.payment' :form-key='this.formItem.paymentId' handlerName='refundDepositPaymentSaveHandler'>
      <f-form-item label='保证金金额' disabled dataType='number' name='payAmount' type='number' :value='formItem.payAmount' />
      <f-form-item label='退款金额' required dataType='number' name='refundAmount' :max='formItem.payAmount' type='number' :value='formItem.refundAmount' />
      <f-form-item label='收款银行' required name='takeBankName' :value='formItem.takeBankName' />
      <f-form-item label='收款账户' required name='takeBankNo' :value='formItem.takeBankNo' />
      <f-form-item label='申请日期' required type='date' name='amountDate' :value='formItem.amountDate' />
      <f-form-item label='备注' type='textarea' name='remark' :value='formItem.remark' />
    </f-form>
    <select-bank-modal ref='bankModal' @onSelectChange='onSelectBankChange'></select-bank-modal>
  </div>
</template>
<script>
import api from "../../js/api"
import SelectBankModal from "@/views/module/haiying/components/select_bank_modal"

export default {
  name: "amountForm",
  props: {},
  data() {
    return {
      api: Object.assign(api, this.api),
      isAdd: true,//是否是添加模式
      loaded: false,//是否加载完成
      formItem: this.getFormItem()
    }
  },
  methods: {
    getFormItem() {
      return {
        depositId: "",
        refundAmount: 0,
        payAmount: 0,
        refundDate: null,
        remark: null
      }
    },
    /**
     * 选择收款银行
     */
    openBankModal() {
      this.$refs["bankModal"].open()
    },
    /**
     * 银行选择回调
     */
    onSelectBankChange(selectedRowKeys, selectedRows) {
      this.$refs.form.getForm().setFieldsValue({ "bankName": selectedRows[0].bankName + "(" + selectedRows[0].bankNo + ")" })
      this.formItem.bankName = selectedRows[0].bankName
      this.formItem.bankId = selectedRowKeys[0]
      this.$forceUpdate()
    },

    //表单赋值
    setData(data) {
      this.$refs.form.resetFields()
      this.formItem = this.getFormItem()
      if (data && data.depositId) {
        this.formItem = data
        this.formItem.takeBankName = data.payBankName
        this.formItem.takeBankNo = data.payBankNo
        this.formItem.remark = ""
        this.isAdd = false
        this.loaded = true
      } else {
        this.loaded = true
      }
    },
    //提交表单
    handleSubmit(callback) {
      this.$refs.form.submit({
        depositId:this.formItem.depositId,
        bankId:this.formItem.bankId
      }, callback)
    }
  },
  created() {
  },
  components: { SelectBankModal }
}
</script>

<style scoped lang='less' rel='stylesheet/less'>

</style>
